1. Field of the Invention
This invention relates generally to computer virtualization and, in particular, to a method and system for maintaining reverse mappings for guest physical pages in a virtualized computer system.
2. Description of the Related Art
The advantages of virtual machine technology have become widely recognized. Among these advantages is the ability to run multiple virtual machines on a single host platform. This makes better use of the capacity of the hardware, while still ensuring that each user enjoys the features of a “complete” computer. Depending on how it is implemented, virtualization also provides greater security, since the virtualization can isolate potentially unstable or unsafe software so that it cannot adversely affect the hardware state or system files required for running the physical (as opposed to virtual) hardware.
As is well known in the field of computer science, a virtual machine (VM) is a software abstraction—a “virtualization”—of an actual physical computer system. FIG. 1 shows one possible arrangement of a computer system 700 that implements virtualization. A virtual machine (VM) 200, which in this system is a “guest,” is installed on a “host platform,” or simply “host,” which will include a system hardware 100, that is, a hardware platform, and one or more layers or co-resident components comprising system-level software, such as an operating system (OS) or similar software layer responsible for coordinating and mediating access to the hardware resources.
As software, the code defining the VM 200 will ultimately execute on the actual system hardware 100. As in almost all computers, this hardware 100 will include one or more CPUs 110, some form of memory 130 (volatile or non-volatile), one or more storage devices such as one or more disks 140, and one or more devices 170, which may be integral or separate and removable.
In many existing virtualized systems, the hardware processor(s) 110 are the same as in a non-virtualized computer with the same platform, for example, the Intel x-86 platform. Because of the advantages of virtualization, however, some hardware processors have also been developed to include specific hardware support for virtualization.
Each VM 200 will typically mimic the general structure of a physical computer and as such will usually have both virtual system hardware 201 and guest system software 202. The virtual system hardware 201 typically includes at least one virtual CPU 210, virtual memory (VMEM) 230, at least one virtual disk (VDISK) 240 or similar virtualized mass storage device, and one or more virtual devices (VDEVICE) 270. Note that a storage disk—virtual 240 or physical 140—is also a “device,” but is usually considered separately because of the important role it plays. All of the virtual hardware components of the VM 200 may be implemented in software to emulate corresponding physical components. The guest system software 202 includes a guest operating system (OS) 220 and drivers 224 as needed, for example, for the various virtual devices 270.
To permit computer systems to scale to larger numbers of concurrent threads, systems with multiple CPUs—physical or logical, or a combination—have been developed. One example is a symmetric multi-processor (SMP) system, which is available as an extension of the PC platform and from other vendors. Essentially, an SMP system is a hardware platform that connects multiple processors to a shared main memory and shared I/O devices. Yet another configuration is found in a so-called “multi-cored” architecture, in which more than one physical CPU is fabricated on a single chip, with its own set of functional units (such as a floating-point unit and an arithmetic/logic unit ALU), and can execute threads independently; multi-cored processors typically share only very limited resources, such as at least some cache. Still another technique that provides for simultaneous execution of multiple threads is referred to as “simultaneous multi-threading,” in which more than one logical CPU (hardware thread) operates simultaneously on a single chip, but in which the logical CPUs flexibly share not only one or more caches, but also some functional unit(s) and sometimes also the translation lookaside buffer (TLB).
Similarly, a single VM may (but need not) be configured with more than one virtualized physical and/or logical processor. By way of example, FIG. 1 illustrates multiple virtual processors 210, 211, . . . , 21m (VCPU0, VCPU1, . . . , VCPUm) within the VM 200. Each virtualized processor in a VM may also be multi-cored, or multi-threaded, or both, depending on the virtualization. This invention may be used to advantage regardless of the number of processors the VMs are configured to have.
If the VM 200 is properly designed, applications (APPS) 260 running on the VM will function as they would if run on a “real” computer, even though the applications are running at least partially indirectly, that is via the guest OS 220 and virtual processor(s). Executable files will be accessed by the guest OS 220 from the virtual disk 240 or virtual memory 230, which will be portions of the actual physical disk 140 or memory 130 allocated to that VM 200. Once an application 260 is installed within the VM 200, the guest OS 220 retrieves files from the virtual disk 240 just as if the files had been pre-stored as the result of a conventional installation of the application. The design and operation of virtual machines in general are known in the field of computer science.
Some interface is generally required between the guest software within a VM 200 and the various hardware components and devices in the underlying hardware platform. This interface—referred to in this text as “virtualization software”—may include one or more software components and/or layers, possibly including one or more of the software components known in the field of virtual machine technology as “virtual machine monitors” (VMMs), “hypervisors,” or virtualization “kernels.” Because virtualization terminology has evolved over time and has not yet become fully standardized, these terms do not always provide clear distinctions between the software layers and components to which they refer. For example, “hypervisor” is often used to describe both a VMM and a kernel together, either as separate but cooperating components or with one or more VMMs incorporated wholly or partially into the kernel itself; however, “hypervisor” is sometimes used instead to mean some variant of a VMM alone, which interfaces with some other software layer(s) or component(s) to support the virtualization. Moreover, in some systems, some virtualization code is included in at least one “superior” VM to facilitate the operations of other VMs. Furthermore, specific software support for VMs is sometimes included in the host OS itself.
Unless otherwise indicated, the invention described below may be used in virtualized computer systems having any type or configuration of virtualization software. Moreover, the invention is described and illustrated below primarily as including one or more virtual machine monitors that appear as separate entities from other components of the virtualization software. This is only for the sake of simplicity and clarity and by way of illustration—as mentioned above, the distinctions are not always so clear-cut. Again, unless otherwise indicated or apparent from the description, it is to be assumed that the invention can be implemented anywhere within the overall structure of the virtualization software.
By way of illustration and example only, the figures show each VM running on a corresponding virtual machine monitor. The description's reference to VMMs is also merely by way of common example. A VMM is usually a software component that virtualizes at least one hardware resource of some physical platform, so as to export a hardware interface to the VM corresponding to the hardware the VM “thinks” it is running on. As FIG. 1 illustrates, a virtualized computer system may (and usually will) have more than one VM, each of which may be running on its own VMM.
The various virtualized hardware components in the VM 200, such as the virtual CPU(s) 210, etc., the virtual memory 230, the virtual disk 240, and the virtual device(s) 270, are shown as being part of the VM 200 for the sake of conceptual simplicity. In actuality, these “components” are often implemented as software emulations included in the VMM 300. One advantage of such an arrangement is that the virtualization software may (but need not) be set up to expose “generic” devices, which facilitate, for example, migration of VM from one hardware platform to another.
Different systems may implement virtualization to different degrees—“virtualization” generally relates to a spectrum of definitions rather than to a bright line, and often reflects a design choice in respect to a trade-off between speed and efficiency on the one hand and isolation and universality on the other hand. For example, “full virtualization” is sometimes used to denote a system in which no software components of any form are included in the guest other than those that would be found in a non-virtualized computer; thus, the guest OS could be an off-the-shelf, commercially available OS with no components included specifically to support use in a virtualized environment.
In contrast, another concept, which has yet to achieve a universally accepted definition, is that of “para-virtualization.” As the name implies, a “para-virtualized” system is not “fully” virtualized, but rather the guest is configured in some way to provide certain features that facilitate virtualization. For example, the guest in some para-virtualized systems is designed to avoid hard-to-virtualize operations and configurations, such as by avoiding certain privileged instructions, certain memory address ranges, etc. As another example, many para-virtualized systems include an interface within the guest that enables explicit calls to other components of the virtualization software. For some, para-virtualization implies that the guest OS (in particular, its kernel) is specifically designed to support such an interface. According to this view, having, for example, an off-the-shelf version of Microsoft Windows XP as the guest OS would not be consistent with the notion of para-virtualization. Others define para-virtualization more broadly to include any guest OS with any code that is specifically intended to provide information directly to the other virtualization software. According to this view, loading a module such as a driver designed to communicate with other virtualization components renders the system  para-virtualized, even if the guest OS as such is an off-the-shelf, commercially available OS not specifically designed to support a virtualized computer system.
Unless otherwise indicated or apparent, this invention is not restricted to use in systems with any particular “degree” of virtualization and is not to be limited to any particular notion of full or partial (“para-”) virtualization.
In addition to the distinction between full and partial (para-) virtualization, two arrangements of intermediate system-level software layer(s) are in general use as, or as part of, the virtualization software—a “hosted” configuration (illustrated in FIG. 2) and a non-hosted configuration (illustrated in FIG. 1). In a hosted virtualized computer system, an existing, general-purpose operating system forms a “host” OS 420 that is used to perform certain input/output (I/O) operations, alongside and sometimes at the request and direction of a virtualization software component such as the VMM 300. The host OS 420 usually includes drivers 424 and supports applications 460 of its own, and the VMM 300 (or similar component) are both able to directly access at least some of the same hardware resources, with conflicts being avoided by a context-switching mechanism. The Workstation product of VMware, Inc., of Palo Alto, Calif., is an example of a hosted, virtualized computer system, which is also explained in U.S. Pat. No. 6,496,847 (Bugnion, et al., “System and Method for Virtualizing Computer Systems,” 17 Dec. 2002).
In addition to device emulators 370, FIG. 2 also illustrates some of the other components that are also often included in the VMM of a hosted virtualization system; many of these components are found in the VMM of a non-hosted system as well. For example, the memory management module 350 manages the translations between guest virtual memory addresses, guest physical memory addresses, and machine memory addresses for the virtual memory (VMEM) 230 of the virtualized system. For another example, exception handlers 330 may be included to help context-switching (see again U.S. Pat. No. 6,496,847), and a direct execution engine 310 and a binary translator 320, often with an associated translation cache 325, may be included to provide execution speed while still preventing the VM 200 from directly executing certain privileged instructions in systems that do not otherwise provide such protection (see U.S. Pat. No. 6,397,242, Devine, et al., “Virtualization System Including a Virtual Machine Monitor for a Computer with a Segmented Architecture,” 28 May 2002).
In many cases, it may be beneficial to deploy VMMs on top of a software layer—a kernel 600—constructed specifically to provide efficient support for the VMs. This configuration is frequently referred to as being “non-hosted.” Compared with a system in which VMMs (or other software components or layers with similar functionality) run directly on the hardware platform (such as shown in FIG. 2), use of a kernel 600 offers greater modularity and facilitates provision of services (for example, resource management) that extend across multiple virtual machines. Compared with a hosted deployment, a kernel 600 may offer greater performance because it can be co-developed with the VMM and be optimized for the characteristics of a workload consisting primarily of VMs/VMMs. The kernel 600 also handles any other applications running on it that can be separately scheduled, as well as any temporary “console” operating system (COS) 420 that, in some systems, is included for such operations as boot the system as a whole or enabling certain user interactions with the kernel. The console OS 420 in FIG. 1 may be of the same type as the host OS 420 in FIG. 2, which is why they are identically numbered—the main difference is the role they play (or are allowed to play, if any) once the virtualized computer system is loaded and running. One example of a non-hosted, virtualized computer system is described in U.S. Pat. No. 6,961,941 (Nelson, et al., “Computer Configuration for Resource Management in Systems Including a Virtual Machine,” 1 Nov. 2005.)
The present invention as described herein may be used to advantage in both a hosted and a non-hosted virtualized computer system, regardless of the degree of virtualization, in which the virtual machine(s) have any number of physical and/or logical virtualized processors. The present invention may also be implemented directly in a computer's primary OS, both where the OS is designed to support virtual machines and where it is not. Moreover, the invention may even be implemented wholly or partially in hardware, for example in processor architectures intended to provide hardware support for virtual machines.
FIG. 3 illustrates virtual memory management and address mapping functions performed by the memory management module 350 and other various components of the virtualized computer system. The guest OS 220 generates a guest OS page table 292. The guest OS page table 292 contains mappings from GVPNs (Guest Virtual Page Numbers) to GPPNs (Guest Physical Page Numbers). Suppose that a guest application 260 attempts to access a memory location having a first GVPN, and that the guest OS 220 has specified in the guest OS page table 292 that the first GVPN is backed by what it believes to be a physical memory page having a first GPPN. The mapping from the first GVPN to the first GPPN is used by the virtual system hardware 201, and it is loaded into a VTLB (Virtual Translation Look-Aside Buffer) 294. The memory management module 350 translates the first GPPN into a corresponding MPN (Machine Page Number), say a first MPN. The memory management module 350 creates a shadow page table 392, and inserts a translation into the shadow page table 392 mapping the first GVPN to the first MPN. In other words, the memory management module creates shadow page tables 392 containing the mapping from the GVPN to the MPN. This mapping from the first GVPN to the first MPN is used by the system hardware 100 and is loaded into the TLB (Translation Look-Aside Buffer) 194 to access the actual hardware storage device that is backing up the GVPN.
Note that the terms “guest virtual page number (GVPN)” and “guest virtual page” are used synonymously herein with the terms “virtual page number” and “virtual page,” respectively, and with the terms “linear page number” and “linear page,” respectively. Also note that the term “guest physical page number” and “guest physical page” are used synonymously herein with the terms “virtual physical page number” and “virtual physical page,” respectively, because they are not real physical page numbers or physical addresses but what the virtual machine 200 believes to be the physical page number and physical address. Finally, note that the terms “machine page number” and “machine page” are used synonymously herein with the terms “physical page number” and “physical page,” respectively, because they are the real physical page number and real physical address corresponding to the machine or hardware memory of the host computer.
When a shadow page table entry 392 is created, the VMM 300 also creates a reverse mapping 394 from the guest (virtual) physical page to the shadow page table entry. In other words, the reverse mappings contain, for each guest (virtual) physical page, the shadow page table entries 392 corresponding to that guest physical page.
Reverse mappings are initially stored in a “physical page descriptor” (not shown) that the VMM 300 maintains to describe the guest physical page that is mapped. The physical page descriptor keeps track of which machine page, if any, is used by the VMM 300 to back the guest physical page. Once the guest physical page has more reverse mappings than will fit into the physical page descriptor, the reverse mappings are moved into what is called a “backmap.” The backmap is shared between all guest physical pages, and typically holds linked lists of fixed sized blocks, one list per guest physical page. Each block stores a fixed number of reverse mappings. Each physical page descriptor has a pointer to the start of the linked list holding its reverse mappings in the backmap.
The reverse mapping is used in various ways. For example, reverse mappings may be used to implement Copy on Write for guest physical memory or to swap out guest physical memory. For another example, “invalidating backing store” is the ability to remove or change the machine page that is used by the VMM 300 to back a particular guest physical page in the VM 200. This changes the guest physical page to machine page mapping that the VMM 300 uses. When the guest physical page to machine page mapping is changed, the VMM 300 needs to remove all mappings based on the old guest physical page to machine page mapping. One of the major places where such old mappings exist is the shadow page tables 392. Removing such old mappings is accomplished by iterating over all of the reverse mappings 394 for the virtual physical page and removing the mappings they point to. For another example, reverse mappings may be used to install “read” or “write” traces to the guest physical page.
For various reasons, there can be a large number of reverse mappings for a single guest (virtual) physical page. For example, the guest OS 220 may use several different guest OS page tables 292 to map the same guest virtual page to the same guest physical page. In such case, a new shadow page table entry 392 and a reverse mapping 394 will be created for each page table 292 in the guest OS 220, resulting in multiple reverse mappings 394 for the same guest physical page. For another example, the guest OS 220 may map the same guest physical page to various different guest virtual pages. In such case too, a new shadow page table entry 392 and a reverse mapping 394 will be created for each page table 292 in the guest OS 220, resulting in multiple reverse mappings 394 for the same guest physical page. In general, there is one reverse mapping 394 for each active shadow page table entry 392.
Needless to say, maintaining these reverse mappings 394 is a major performance overhead for the virtualized computer system. Some of this overhead can be reduced by improving or simplifying the data structures for such reverse mappings 394, as in the conventional art. However, there is a limit to the efficiency of such data structures.
Therefore, there is a need for a technique for identifying certain guest physical pages that do not require storage of reverse mappings, thereby reducing the overhead of the virtualized computer system. There is also a need for a technique for recovering from misidentification of such guest physical pages that do not require storage of reverse mappings.